package com.yzh.homework;

import java.util.Arrays;

/**
 * @author 于振晗
 * @title: InsertSort
 * @description: TODO 插入排序
 * @date 2020年09月01日
 * @path com.yzh.homework
 */
public class InsertSort {
    public static void main(String[] args) {
        int [] arr = {7,4,5,6,7,5,9,1,2,4,111,58};
        for (int i = 0; i < arr.length-1; i++) {
            if(arr[i]>arr[i+1]){
                for(int j = i+1;j>0;j--){
                    if(arr[j]<arr[j-1]){
                        int temp = arr[j];
                        arr[j] = arr[j-1];
                        arr[j-1] = temp;
                    }
                }
            }
        }

        System.out.println(Arrays.toString(arr));
    }
}
